package com.moon.mapper;

import com.moon.pojo.Emp;
import com.moon.pojo.EmpQueryParam;
import com.moon.pojo.JobOption;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id")
    Long count();


    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id limit #{start},#{pageSize}")
    List<Emp> page(int start, Integer pageSize);

    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id " +
            "order by entry_date desc ")
    List<Emp> pageWithPageHelper();

    List<Emp> pageWithPageHelperAndXml(EmpQueryParam empQueryParam);


    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getEmpById(Integer id);

    void updateEmp(Emp emp);

    @MapKey("job")
    List<Map<Object, Object>> countEmpJobData();

    @MapKey("gender")
    List<Map<Object, Object>> countEmpGenderData();

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectOne(Emp emp);
}
